#include<iostream>

using namespace std;

typedef struct student
{
    int a,b,c,all;
} student ;


int main(int argc, char const *argv[])
{
    int N,count=0;
    scanf("%d",&N);
    student students[N];
    for (int i = 0; i < N; i++)
    {
        scanf("%d %d %d",&students[i].a,&students[i].b,&students[i].c);
        students[i].all =  students[i].a + students[i].b + students[i].c;
    }
    
    for (int i = 0; i < N; i++)
    {
        for (int j = N-1; j > i; j--)
        {
            if(abs(students[i].a-students[j].a)<=5&&abs(students[i].b-students[j].b)<=5
            &&abs(students[i].c-students[j].c)<=5&&abs(students[i].all-students[j].all)<=10)
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}

